package org.mybatis.jpetstore;

import cn.webwheel.DefaultMain;
import cn.webwheel.WebContext;
import cn.webwheel.WebContextAware;
import org.springframework.web.context.support.WebApplicationContextUtils;

public class Main extends DefaultMain {
    @Override
    protected void init() {
        super.init();

        autoMap("org.mybatis.jpetstore.web");
    }

    @Override
    public <T> T createAction(WebContext ctx, Class<T> type) {
        T bean = WebApplicationContextUtils.getWebApplicationContext(servletContext).getBean(type);
        if (bean instanceof WebContextAware) {
            ((WebContextAware) bean).setWebContext(ctx);
        }
        return bean;
    }
}
